<template>
	<view>
		<img :src="item.image" alt="" style="width: 100vw">
		<text>{{ item.title }}</text>
		<text>{{ item.price }}</text>
		<button @click="addCart({
			...item,
			state: true,
			count: 1
		})">加入购物车</button>
	</view>
</template>

<script>
	import { mapMutations } from 'vuex'
	export default {
		data() {
			return {
				id: '',
				item: {}
			};
		},
		onLoad({ id }) {
			this.id = id
			this.getDetail()
		},
		methods: {
			...mapMutations('cart', ['addCart']),
			async getDetail() {
				const resp = await uni.request({
					url: 'http://localhost:3000/list/' + this.id
				})
				this.item = resp.data
			}
		}
	}
</script>

<style lang="scss">

</style>
